﻿

<!DOCTYPE html>
<html lang="en">

<head>
    <!-- IIS Virtual Directory name -->
    <!--<base href="/JSViewer_MVC_Core/">-->

    <meta charset="utf-8">
    <link rel='shortcut icon' type='image/x-icon' href='favicon.ico' />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="theme-color" content="#000000">
    <title>JS Viewer</title>
    <link href="jsViewer.min.css" rel="stylesheet">
    <link href="index.css" rel="stylesheet">
</head>

<body onload="loadViewer()">
    <div style="width: 100%; overflow-x: hidden">
        <div style="float:left; width: 0pt" class="main-nav navbar">
            <div id='list-heading'>Select report</div>
            <ul id="reportsList" class="nav navbar-nav"></ul>
        </div>

        <div style="float:right;width:calc(100% - 0pt)">
            <div id="viewerContainer">
            </div>
        </div>
    </div>
    <script type="text/javascript" src="jsViewer.min.js"></script>
    <script type="text/javascript" src="jquery-3.6.3.min.js"></script>
    <script type="text/javascript">
        debugger;
        var query = window.location.search.substring(1).split('&');
        var reportCode = "";
        var hospitalCode = "";
        var reportName = "";
        var systemCode=""
        var param=[];
        for (var i = 0; i < query.length; i++) {
            var arr = query[i].split('=');
            var array = {
                name: '', values: []
            };
            if (arr[0] == "tempCode") { reportCode = arr[1]; continue; };
            if (arr[0] == "hospitalCode" || arr[0] == "orgId") { hospitalCode = arr[1] };
            if (arr[0] == "xtdm" || arr[0] == "systemCode") { systemCode = arr[1] };
            array.name = arr[0];
            array.values.push(decodeURIComponent(arr[1]));
            param.push(array);
        }
        let viewer;
        let kyreportInfo = { templateId: "", hospitalCode: "", reportdec: "" };

        function loadViewer() {
            if (reportCode && hospitalCode != "" && systemCode!="") {
                let temUrl = "GetTempLateData/" + reportCode + "/" + hospitalCode + "/" + systemCode;
                $.ajax({
                    type: "get",
                    url: temUrl,
                    dataType: "json",
                    async: false,
                    success: function (res) {
                        debugger;
                        if (res.Code == 0) {
                            reportName = res.Data;
                        }
                    }
                })

                viewer = GrapeCity.ActiveReports.JSViewer.create({
                    element: '#viewerContainer',
                    reportID: reportName,//报表名称
                    reportService: {
                        url: 'api/reporting/', //调用报表服务url前缀
                    },
                    reportParameters: param,
                    parametersPanel: { location: 'top' }
                });
            }
            else {
                viewer = GrapeCity.ActiveReports.JSViewer.create({
                    element: '#viewerContainer',
                    parametersPanel: { location: 'top' }
                });
            }
            viewer.sidebar.toggle(false);
            const pdfExportButton = {
                    key: 'pdfExport',
                    iconCssClass: 'mdi mdi-file',
                    text: "导出PDF",
                    title: "导出",
                    checked: true,
                    enabled: true,
                    action: function (item) {
                        var settings = {
                            title: 'Invoice List',
                            userPassword: 'user_Pwd'
                        };
                        var cancelCallback = function () {
                            return false;
                        }
                        viewer.export('pdf', downloadReport, true, { Title: '导出PDF' });
                        var downloadReport = function (uri) {
                            var newWin = null;
                            try {
                                newWin = window.open(uri);
                            } catch (e) { }

                            if (!newWin) {
                                window.location = uri;
                            }
                        }
                    }
                };
            viewer.toolbar.desktop.addItem(pdfExportButton);
            var layout = ['$navigation', '$history', '$fullscreen', '$split', '$print','pdfExport', '$refresh', '$galleymode', '$mousemode', '$split', '$continuousmode', '$singlepagemode', '$zoom', '$split'];
            viewer.toolbar.desktop.layout(layout);
            localize();
        }
        window.addEventListener('message', function (e) {
            if (e.source != window.parent) { return; }
            let data = e.data;
            kyreportInfo.templateId = data.ReportID;
            kyreportInfo.hospitalCode = data.HospitalCode;
            kyreportInfo.reportdec = data.mc;
            kyreportInfo.ly = data.ly;
            ShowReports(kyreportInfo);

        })
        function ShowReports(kyreportInfo) {
           
            if (kyreportInfo) {
                const templateId =kyreportInfo.templateId;
                const hospitalCode = kyreportInfo.hospitalCode;
                const reportdec = kyreportInfo.reportdec;
                let reportName = templateId + "_" + hospitalCode + "_" + reportdec;
                let initializeReportUrl = "InitReport/" + templateId + "/" + hospitalCode;
                $.ajax({
                    type: "get",
                    url: initializeReportUrl,
                    dataType: "json",
                    success: function (res) {
                        debugger;
                        if (res.Code == 0) {
                            viewer.openReport(reportName);
                        }
                    }
                })
            }

        }

        function localize() {
            if (navigator.language === 'ja') {
                document.getElementById("list-heading").innerText = "レポートを選択";
                document.title = "JSビューア";
            }
        }
    </script>
</body>
</html>